package zhuyun.code.launcheractivity.view.widget.component

import android.view.View
import zhuyun.code.launcheractivity.view.adapter.BaseViewHolder

/**
 * @author: Administrator
 * @date: 2021/12/9
 */
abstract class LoadMoreView {
    companion object{
        const val STATUS_DEFAULT = 1
        const val STATUS_LOADING = 2
        const val STATUS_FAIL = 3
        const val STATUS_END = 4
    }
    var mLoadMoreStatus = STATUS_DEFAULT
    fun convert(holder:BaseViewHolder){
        when(mLoadMoreStatus){
            STATUS_LOADING->{
                visibleLoading(holder,true)
                visibleLoadFail(holder,false)
                visibleLoadEnd(holder,false)
            }
            STATUS_FAIL->{
                visibleLoading(holder,false)
                visibleLoadFail(holder,true)
                visibleLoadEnd(holder,false)
            }
            STATUS_END->{
                visibleLoading(holder,false)
                visibleLoadFail(holder,false)
                visibleLoadEnd(holder,true)
            }
            STATUS_DEFAULT->{
                visibleLoading(holder,false)
                visibleLoadFail(holder,false)
                visibleLoadEnd(holder,false)
            }
        }
    }

    private fun visibleLoading(holder: BaseViewHolder,visible:Boolean){
        holder.setVisibility(getLoadingViewId(),if(visible) View.VISIBLE else View.GONE)
    }

    private fun visibleLoadFail(holder: BaseViewHolder,visible: Boolean){
        holder.setVisibility(getLoadFailViewId(),if(visible) View.VISIBLE else View.GONE)
    }

    private fun visibleLoadEnd(holder: BaseViewHolder,visible: Boolean){
        holder.setVisibility(getLoadEndViewId(), if(visible) View.VISIBLE else View.GONE)
    }


    abstract fun getLayoutId():Int
    abstract fun getLoadingViewId():Int
    abstract fun getLoadFailViewId():Int
    abstract fun getLoadEndViewId():Int

}